package GUI;

import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.JTextField;

/**
 * view all reports options for a specific period
 * @author Lidor
 *
 */
@SuppressWarnings("serial")
public class ReportsGUI extends JPanel {
	
	public MainFrame mf;
    public DefaultTableModel searchTableModel1;
    private JScrollPane scrollPane1;
    public JTable table1;
	

	/**
	 * Create the panel.
	 * M main frame of the program
	 */
	public ReportsGUI(MainFrame M) {
		setPreferredSize(new Dimension(600, 520));
		setMaximumSize(new Dimension(600, 520));
		setMinimumSize(new Dimension(600, 520));
		setLayout(null);
		this.mf=M;
		
		JLabel lblReports = new JLabel("Reports");
		lblReports.setFont(new Font("Segoe UI", Font.BOLD, 16));
		lblReports.setBounds(255, 12, 82, 23);
		add(lblReports);
		
		JLabel lblSystemData = new JLabel("System Data:");
		lblSystemData.setBounds(53, 63, 108, 14);
		add(lblSystemData);
		
		JButton btnUsers = new JButton("Users");
		btnUsers.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				for (int i = mf.managerMain.reports.searchTableModel1.getRowCount() - 1; i >= 0; i--){ 
					mf.managerMain.reports.searchTableModel1.removeRow(i);
				 }
				 ArrayList<Object> send = new ArrayList<Object>();
				 send.add("3");
				 send.add("UserReport");
				 mf.client.accept(send);
			}
		});
		btnUsers.setBounds(171, 59, 89, 23);
		add(btnUsers);
		
		JButton btnEmployees = new JButton("Employees");
		btnEmployees.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
	
					for (int i = mf.managerMain.reports.searchTableModel1.getRowCount() - 1; i >= 0; i--){ 
						mf.managerMain.reports.searchTableModel1.removeRow(i);
					 }
					 ArrayList<Object> send = new ArrayList<Object>();
					 send.add("3");
					 send.add("EmployeeReport");
					 mf.client.accept(send);
			}
		});
		btnEmployees.setBounds(310, 59, 101, 23);
		add(btnEmployees);
		
		JLabel lblCreateReports = new JLabel("Create Reports:");
		lblCreateReports.setFont(new Font("Segoe UI", Font.BOLD, 14));
		lblCreateReports.setBounds(239, 286, 108, 25);
		add(lblCreateReports);
        
        searchTableModel1= new DefaultTableModel();
        searchTableModel1.addColumn("ID");
        searchTableModel1.addColumn("Name");
        searchTableModel1.addColumn("Phone");
        searchTableModel1.addColumn("Email");
        searchTableModel1.addColumn("Password");
        searchTableModel1.addColumn("Card Status");

		scrollPane1 = new JScrollPane();
		scrollPane1.setBounds(53, 89, 488, 164);
		add(scrollPane1);
		
		table1= new JTable(searchTableModel1){
		        
		        public boolean isCellEditable(int rowIndex, int colIndex) {
		                  return false; //Disallow the editing of any cell
		                  }
		                  };
		
        
        scrollPane1.setViewportView(table1);
        table1.setRowSelectionAllowed(true);
        table1.setVisible(true);
        
        String[] typeCombo = {"Activity", "Borrows", "Delays", "Custom"};
		
		JButton btnActivity = new JButton("Activity Report");
		btnActivity.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				mf.managerMain.reports.setVisible(false);
				mf.managerMain.cardManaging.setVisible(false);
				mf.managerMain.activityGUI.setVisible(true);
				mf.managerMain.activityGUI.init();
				mf.librarianMain.bookReturn.setVisible(false);
				mf.librarianMain.bookBorrow.setVisible(false);
				mf.librarianMain.manualExtend.setVisible(false);
				mf.librarianMain.searchBook.setVisible(false);
				mf.librarianMain.viewUser.setVisible(false);
				mf.librarianMain.registerNewUser.setVisible(false);
			}
		});
		btnActivity.setBounds(10, 335, 169, 54);
		add(btnActivity);
		
		JButton btnRegularBookBorrows = new JButton("Regular Book Borrows");
		btnRegularBookBorrows.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				mf.managerMain.regBorrowGUI.init();
				mf.managerMain.reports.setVisible(false);
				mf.managerMain.cardManaging.setVisible(false);
				mf.managerMain.activityGUI.setVisible(false);
				mf.librarianMain.bookReturn.setVisible(false);
				mf.librarianMain.bookBorrow.setVisible(false);
				mf.librarianMain.manualExtend.setVisible(false);
				mf.librarianMain.searchBook.setVisible(false);
				mf.librarianMain.viewUser.setVisible(false);
				mf.librarianMain.registerNewUser.setVisible(false);
				mf.managerMain.regBorrowGUI.lblRegularBookBorrows.setVisible(true);
				mf.managerMain.regBorrowGUI.lblRegularBookBorrows1.setVisible(false);
				ArrayList<Object> send = new ArrayList<>();
				send.add("3");
                send.add("RegBooks");
                mf.client.accept(send);
			}
		});
		btnRegularBookBorrows.setBounds(215, 335, 169, 54);
		add(btnRegularBookBorrows);
		
		JButton btnRatedBookBorrows = new JButton("Rated Book Borrows");
		btnRatedBookBorrows.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				mf.managerMain.regBorrowGUI.init();
				mf.managerMain.reports.setVisible(false);
				mf.managerMain.cardManaging.setVisible(false);
				mf.managerMain.activityGUI.setVisible(false);
				mf.librarianMain.bookReturn.setVisible(false);
				mf.librarianMain.bookBorrow.setVisible(false);
				mf.librarianMain.manualExtend.setVisible(false);
				mf.librarianMain.searchBook.setVisible(false);
				mf.librarianMain.viewUser.setVisible(false);
				mf.librarianMain.registerNewUser.setVisible(false);
				mf.managerMain.regBorrowGUI.lblRegularBookBorrows1.setVisible(true);
				mf.managerMain.regBorrowGUI.lblRegularBookBorrows.setVisible(false);

				ArrayList<Object> send = new ArrayList<>();
				send.add("3");
                send.add("RatedBooks");
                mf.client.accept(send);
			}
		});
		btnRatedBookBorrows.setBounds(421, 335, 169, 54);
		add(btnRatedBookBorrows);
		
		ImageIcon img = new ImageIcon(getClass().getResource(
                "/util/grad2.jpg"));
		JLabel picLabel = new JLabel(img);
		picLabel.setLocation(0, 0);
		picLabel.setSize(715, 597);
		add(picLabel);
		

		
	}		
}
